
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The impact of divorce laws on the equilibrium in the marriage market.
% Reynoso
% April 2024
%
% This file inputs estimates and solves for the new initial Pareto 
% weights under Unilateral Divorce full model, with divorce settlements,
% and without renegotiation.
%  
% Data: PSID 1968-1992
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%------------------------ Replication Path -------------------------------%

clc
clear all

%--- Indicate location of Replication folder:
%replication_location = 'C:\update_with_your_path';

%------------------------ Preliminaries ----------------------------------%

%--- Working directory
cd ([replication_location,'\Impact_UD']);

%--- Path for estimates
estimates_dir = [replication_location,'\Outputs\MCD\'];

%--- Path for functions
addpath(genpath([replication_location,'\Impact_UD\Inputs']));

%--- Load estimation resutls
load([estimates_dir, 'outputs_mcd']); 
params=X;

%--- Path to store
output_dir = [replication_location,'\Outputs'];

load([output_dir, '\MCD\moments_mc']);
load('inputs_ud');
singles_moments_mc = [model_moments_mc(19:24) model_moments_mc(61:66) model_moments_mc(103:108) model_moments_mc(145:150)];
lambda_mcd = [params(55:63)' params(64:72)' params(73:81)' params(82:90)'];

%------------------------ Solve equilibrium under UD ---------------------%

%--- UD full model
lambda_ud = zeros(n_g,4); 
for mkt=1:4
    [lambda_ud(:,mkt)]=ud_fixedpoint(n_g,singles_moments_mc(:,mkt), data_f(:,mkt), data_m(:,mkt), lambda_mcd(:,mkt), Uf_grid_ud, Um_grid_ud, U_f0_ud, U_m0_ud, Lini_grid_norep);
end 
save(fullfile(output_dir,'\UD\equil_ud'),'lambda_ud');

%--- UD with divorce settlement
lambda_ud = zeros(n_g,4); 
for mkt=1:4
    [lambda_ud(:,mkt)]=ud_fixedpoint(n_g,singles_moments_mc(:,mkt), data_f(:,mkt), data_m(:,mkt), lambda_mcd(:,mkt), Uf_grid_ud_ds, Um_grid_ud_ds, U_f0_ud_ds, U_m0_ud_ds, Lini_grid_mech);
end 
save(fullfile(output_dir,'\Divorce_settlement\equil_ud_DivorceSettlement'),'lambda_ud');
      
%--- UD with commitment with initial Pareto weights
lambda_ud = zeros(n_g,4);
for mkt=1:4 
    [lambda_ud(:,mkt)]=ud_fixedpoint(n_g,singles_moments_mc(:,mkt), data_f(:,mkt), data_m(:,mkt), lambda_mcd(:,mkt), Uf_grid_ud_c, Um_grid_ud_c, U_f0_ud_c, U_m0_ud_c, Lini_grid_mech);
end 
save(fullfile(output_dir,'\Commitment\equil_ud_Commitment'),'lambda_ud');




